import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:kq_flutter_core_widget/utils/log.dart';

/// 推送调用原生工具类
class PushNativeUtil {

  static const _methodChannelName = 'flutter.keqiang.com/push';

  static const _platformMethod = MethodChannel(_methodChannelName);

  /// 打开推送通道
  ///
  /// 注意：Android端的FlutterActivity 必须实现[IKqPush]
  static turnOnPushChannel() async {
    try {
      _platformMethod.invokeMethod(
        'turnOnPushChannel',
        {},
      ).then(
        (value) => {},
      );
    } on PlatformException catch (e) {
      debugPrint(e.message);
    }
  }

  /// 关闭推送通道
  ///
  /// 注意：Android端的FlutterActivity 必须实现[IKqPush]
  static turnOffPushChannel() async {
    try {
      _platformMethod.invokeMethod(
        'turnOffPushChannel',
        {},
      ).then(
        (value) => {},
      );
    } on PlatformException catch (e) {
      debugPrint(e.message);
    }
  }

  /// 设置别名
  ///
  /// 注意：Android端的FlutterActivity 必须实现[IKqPush]
  static setAlias(String alias) async {
    try {
      _platformMethod.invokeMethod(
        'setAlias',
        {'alias': alias},
      ).then(
        (value) => {},
      );
    } on PlatformException catch (e) {
      debugPrint(e.message);
    }
  }

  /// 移除别名
  ///
  /// 注意：Android端的FlutterActivity 必须实现[IKqPush]
  static removeAlias(String alias) async {
    try {
      _platformMethod.invokeMethod(
        'removeAlias',
        {'alias': alias},
      ).then(
        (value) => {},
      );
    } on PlatformException catch (e) {
      debugPrint(e.message);
    }
  }
}
